package view;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionEvent;


/**
 * This is the Pending Request Details GUI extends AbstractGUI 
 * @author Tal Panika	
 */ 
public class PendingRequestDetailsGUI extends AbstractGUI
{

		
		private JTextArea  DetailsTextArea = null;
		private JButton approveButton = null;
		private JButton denyButton = null;
		private JPanel contentPane=null;
		private JLabel wrnMessage=null;
		
		/**
		 * This is PendingRequestDetailsGUI constructor.
		 * 
		 */
		
		public PendingRequestDetailsGUI (String title)
		{ 
			 //Pending Request Details Registration panel
			   contentPane=new JPanel();	
			   
			   contentPane.setBorder(new TitledBorder(null, title, TitledBorder.LEADING, TitledBorder.TOP, null, null));	
			   contentPane.setLayout(null);
			   contentPane.setOpaque(true);
			   contentPane.add(getDetailsArea());
			   contentPane.add(getApproveButton());
			   contentPane.add(getDenyButton());
			   contentPane.add(getBackButton());      
				contentPane.add(getWrnMessage());
		         
		         //Frame
			        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
			        this.setTitle(title+" Window");
			        this.setContentPane(contentPane);  
				    this.setLocationRelativeTo(null); //This will center the JFrame in the middle of the screen
			        this.setLocationByPlatform(true);
			        this.setSize(500, 500);
			        this.setVisible( true ); // display frame
		               
		  }
			
		/**
		 * This method initializes Details Area
		 */
		private JTextArea  getDetailsArea() {
			if (DetailsTextArea == null) {
				DetailsTextArea = new JTextArea();
				DetailsTextArea.setWrapStyleWord(true);
				DetailsTextArea.setLineWrap(true);
				DetailsTextArea.setBorder(BorderFactory.createLineBorder(Color.BLACK));
				DetailsTextArea.setBounds(new Rectangle(50, 50, 400, 265));
			}
			return DetailsTextArea;
		}
		
		/**
		 * This method initializes Approve Button	
		 */
		private JButton getApproveButton() {
			if (approveButton == null) {
				approveButton = new JButton();
				approveButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
					}
				});
				approveButton.setBounds(new Rectangle(80, 347, 100, 35));
				approveButton.setText("Approve");
			}
			return approveButton;
		}
		
		/**
		 * This method initializes Deny Button	
		 */
		private JButton getDenyButton() {
			if ( denyButton == null) {
				 denyButton = new JButton();
				 denyButton.setBounds(new Rectangle(321, 347, 100, 35));
				 denyButton.setText("Deny");
			}
			return  denyButton;
		}
		
		/**
		 * This method initializes Back Button	
		 */
		private JButton getBackButton() {
			if (backButton == null) {
				backButton = new JButton();
				backButton.setBounds(new Rectangle(200, 400,100, 35));
				backButton.setText("Back");
			}
			return backButton;
		}
		
		/**
		 * This method creates warning message if currently is null.
		 * @return JLabel type.
		 */
		private JLabel getWrnMessage() {
			if (wrnMessage == null) {
				wrnMessage = new JLabel();
				wrnMessage.setForeground(Color.RED);
				wrnMessage.setBounds(70, 16, 320, 23);
				wrnMessage.setVisible(false);
			}
			return wrnMessage;
		}
		
		/**
		 * *********************************Public Methods 
		 */
		
		/**
		 * This method display Warning Message.
		 * @param void	 
		 * */
		
		public void displayWrnMessage(String msg){
			wrnMessage.setText(msg);
			wrnMessage.setVisible(true);
		}
		
		
		/**
		 * This set setDetailsField Area.
		 * @param String Msg 
		 * */
		
		public void setDetailsArea(String msg){
			DetailsTextArea.setText(msg);
			DetailsTextArea.setVisible(true);
		}
		
		/**
		 * This method return Details Area
		 */
		public JTextArea  getsDetailsArea() {
			return DetailsTextArea;
		}
		
		
		/**
		 * This method add action listener to Approve button.
		 * @param listener
		 */
		public void addApproveActionListener(ActionListener listener){
			approveButton.addActionListener(listener);
		}
		/**
		 * This method add action listener to deny button.
		 * @param listener
		 */
		public void addDenyActionListener(ActionListener listener){
			denyButton.addActionListener(listener);
		}
		
		
		/**
		 * This method return -simulate back button pressed .
		 * @param listener
		 */
		public void clickBackButton()
		{
			this.getBackButton().doClick();
		}
		

}
